package com.yzy.mall.repository


import com.yzy.baselibrary.base.BaseLiveData
import com.yzy.baselibrary.base.BaseViewModel

class SaveViewModel : BaseViewModel() {
    private val ganRepository: CardRepository by lazy { CardRepository() }
    private val _bannerAndArticleResult: BaseLiveData<BaseUiModel<Any>> = BaseLiveData()
    val uiState: BaseLiveData<BaseUiModel<Any>> get() = _bannerAndArticleResult

    fun exchangeInfo(  saveBean: SaveBean) {
        emitUiState(true)
        launchOnlyresult({ ganRepository.exchangeInfo(saveBean) }, {
            emitUiState(false,it)
        })
    }

    private fun emitUiState(
        showLoading: Boolean = false,
        success: Any? = null
    ) {
        val uiModel = BaseUiModel(showLoading = showLoading, success = success)
        _bannerAndArticleResult.update(uiModel)
    }
}